package com.gouaixin.bee.beeframework2.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gouaixin.bee.beeframework2.R;
import com.gouaixin.bee.beeframework2.bean.MessageBean;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * Created by Administrator on 2015/3/24.
 */

//聊天列表的适配器
public class MessageAdapter extends BaseAdapter {
    ArrayList<MessageBean> datas;
    Context context;
    LayoutInflater mInflater;

    int number=10;


    public MessageAdapter(Context context,ArrayList<MessageBean> datas){
        this.context=context;
        setData(datas);
        mInflater = LayoutInflater.from(context);
    }

    public void setData(ArrayList<MessageBean> datas) {
        this.datas=datas;
    }

    public void setNumer(int number)
    {
        this.number=number;
    }
    @Override
    public int getCount() {
//        return datas.size();
        return number;
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){

            if(position%2==0){
                convertView = mInflater.inflate(R.layout.item_liaotian_right, null);//发送消息的视图项
            }else{
                convertView = mInflater.inflate(R.layout.item_liaotian_left, null);//接受消息的视图项
            }


            viewHolder=new ViewHolder();
            viewHolder.time= (TextView) convertView.findViewById(R.id.time);
            viewHolder.content= (TextView) convertView.findViewById(R.id.content);
            viewHolder.icon= (ImageView) convertView.findViewById(R.id.icon);

            convertView.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) convertView.getTag();
        }


        viewHolder.time.setText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
//        viewHolder.time.setText("2012-12-12 12:12:12");
////        viewHolder.content.setText(messageBean.getAps().getAlert());
//        viewHolder.content.setText("这是测试消息");

        return convertView;
    }

    class ViewHolder{
        TextView time;
        ImageView icon;
        TextView content;

    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

//    @Override
//    public int getItemViewType(int position) {
////        MessageBean messageBean=datas.get(position);
////
////        if(messageBean.getfId()== MyMainActivity.objectID){
////            return 0;//发送消息
////        }else {
////            return 1;//接受消息
////        }
//    }
}
